//
//  BeautifyViewController.m
//  IconMaster
//
//  Created by mac on 2017/9/4.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "BeautifyViewController.h"
#import "BackGroudViewController.h"
#import "BolardViewController.h"
#import "ZhaungshiViewController.h"
#import "SpiteView.h"
#import "BackGroundView.h"
@interface BeautifyViewController ()
@property (weak, nonatomic) IBOutlet BackGroundView *backGroundView;
@property (weak, nonatomic) IBOutlet UIImageView *backImgView;
@property (weak, nonatomic) IBOutlet UIImageView *blordImgView;


@property (weak, nonatomic) IBOutlet JXButton *backgroundBtn;
@property (weak, nonatomic) IBOutlet JXButton *wordBtn;
@property (weak, nonatomic) IBOutlet JXButton *blordBtn;
@property (weak, nonatomic) IBOutlet JXButton *garnishBtn;

@property (nonatomic, strong) SpiteView *spiteView;

@end

@implementation BeautifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.backImgView.image = self.image;
    // Do any additional setup after loading the view.
}

- (void)setButtonTitleAndImg{

    
}

- (IBAction)backgroundAction:(id)sender {
    BackGroudViewController *backVC = [[BackGroudViewController alloc] init];
    [self presentViewController:backVC animated:YES completion:nil];
     backVC.returnValueBlock = ^(UIImage *backImage) {
         self.backImgView.image = backImage;
     };
}
- (IBAction)blordAction:(id)sender {
    BolardViewController *boladVC = [[BolardViewController alloc] init];
    [self presentViewController:boladVC animated:YES completion:nil];
    boladVC.returnValueBlock = ^(UIImage *backImage) {
        self.blordImgView.image = backImage;
    };
}
- (IBAction)garnishAction:(id)sender {
    
    ZhaungshiViewController *gainsVC = [[ZhaungshiViewController alloc] init];
    [self presentViewController:gainsVC animated:YES completion:nil];
    gainsVC.returnValueBlock = ^(UIImage *backImage) {
        //
        [self creatGainsView:backImage];
    };
}
- (void)creatGainsView:(UIImage *)image{

    self.spiteView = [[SpiteView alloc] initWithFrame:self.backGroundView.frame withImage:image];
    [self.backGroundView addSubview:self.spiteView];
    [self.view bringSubviewToFront:self.spiteView];
}
- (IBAction)wordAction:(id)sender {
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
     UITouch* touch = [touches anyObject];
     CGPoint point = [touch locationInView:self.view];
    if (CGRectContainsPoint(self.backGroundView.frame, point)) {
        //
//        NSLog(@"在");
    }else{
//    NSLog(@"不在");
        self.spiteView.cancelImageView.hidden = YES;
        self.spiteView.rotateImageView.hidden = YES;
        for (UIView *view in self.spiteView.subviews) {
            if (view.width == 2 || view.height == 2) {
                [view removeFromSuperview];
            }
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
